import java.awt.EventQueue;

import javax.swing.JFrame;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JTextPane;
import java.awt.FlowLayout;
import javax.swing.SwingConstants;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class MainWindow {

    QuestionProvider provider = MainClass.questionProvider;
    
    private JFrame frame;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
	MainClass.addQuestionsInArray();
	
	EventQueue.invokeLater(new Runnable() {
	    public void run() {
		try {
		    MainWindow window = new MainWindow();
		    window.frame.setVisible(true);
		} catch (Exception e) {
		    e.printStackTrace();
		}
	    }
	});
    }

    /**
     * Create the application.
     */
    public MainWindow() {
	initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
	frame = new JFrame();
	frame.setBounds(100, 100, 550, 76);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.getContentPane().setLayout(new BorderLayout(0, 0));
	
	JPanel panel = new JPanel();
	panel.setBorder(new TitledBorder(null, "Question", TitledBorder.LEADING, TitledBorder.TOP, null, null));
	frame.getContentPane().add(panel, BorderLayout.CENTER);
	panel.setLayout(new BorderLayout(0, 0));
	
	final JTextPane textPane = new JTextPane();
	panel.add(textPane, BorderLayout.CENTER);
	
	JPanel panel_1 = new JPanel();
	frame.getContentPane().add(panel_1, BorderLayout.EAST);
	panel_1.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
	
	JButton btnNewButton = new JButton("Next question");
	btnNewButton.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent e) {
		    textPane.setText(provider.nextQuestion().getQuestion());
		}
	});
	panel_1.add(btnNewButton);
    }

}
